package ttl;
import java.io.IOException;  
import java.util.HashMap;
import java.util.Map;
  
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;  
import com.rabbitmq.client.Connection;  
import com.rabbitmq.client.ConnectionFactory;  

public class MsgTTL {
	 private final static String QUEUE_NAME = "hello";  
	 private final static String HOST = "10.20.53.25";  
	/**
	 * @param args
	 * @throws IOException 
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws IOException, InterruptedException {
			ConnectionFactory factory = new ConnectionFactory();  
		 	factory.setHost(HOST);
	        Connection connection = factory.newConnection();  
	        Channel channel = connection.createChannel();  
	  
	        AMQP.BasicProperties properties = new AMQP.BasicProperties();
	        properties.setExpiration("6000");//This properties set for msg, 
	        							     //query can also has per-queue TTL setting.
	        								 //When both a per-queue and a per-message TTL are specified, 
	        								 //the lower value between the two will be chosen.
	        
	        for(int index=0;index<10; index++){
		        String message = "Msg info : "+index;  
		        channel.basicPublish("", QUEUE_NAME, properties, message.getBytes());
		        System.out.println(HOST +" [x] Sent '" + message + "'");
		        Thread.sleep(5000);
	        }
	  
	        channel.close();  
	        connection.close();  

	}

}
